Counting Solutions to Quadratic Equation Modulo Prime

This result relates to the fact that "square roots" modulo p where p is prime come in pairs. This is incredibly useful when counting quadratic residues modulo prime.

Theorem

Given an odd prime p and a0(modp), the equation:

x2a(modp)

has either 2 or 0 solutions modulo p.

Proof

Consider xZp, a solution to the equation:

x2a(modp)

where a0(modp).

Let y be another such solution. Then consider that

x2y2aa0(modp)(xy)(x+y)0(modp)(1)xy0(modp)orx+y0(modp)xy(modp)orxy(modp).

Where (1) follows since p being prime implies Zp is a field implies that it has the zero product property since every division ring is a domain. In the case where p is not a prime, we can only conclude that any two solutions sum to or differ by a zero divisor.

Hence y is another solution if and only if it is x or x. Then consider (in the interest of showing that these are distinct)

xx(modp)2x0(modp)x0(modp)

where we once again apply the zero product property for this last step (or more primitively that p being odd implies that gcd(2,p)=1 and hence we may multiply by a1).

Given that a0(modp), we have that x0(modp) once again from the zero product property applied to xx.

Then, from the above, this implies that xx(modp), so we have exactly two distinct solutions if any solutions exist.


We can also find a nice expression for the number of solutions to such an equation, with less restrictions on a, however this result depends on Euler's criterion which the above is used to proof (for the proof in this vault).

Assuming we have this result now though, then we have the following corollary.

Corollary

Given an odd prime p and any integer a, the equation:

x2a(modp)

has 1+ap12 solutions.


Non-Prime Modulus

Above it was shown that for a non-prime modulus the condition on square roots is that they sum to or differ by a zero divisor. Here is an explicit example showing that there may be more square roots in this case, and how they pair as described above.

Example
x21(mod8)

has 4 solutions.

In this case we have that:

020(mod8)12(1)21(mod8)22(2)24(mod8)32(3)21(mod8)42(4)20(mod8)

and hence the solutions are the residue classes of 1, 1, 3 and 3.

In the case of Z8 we have zero divisors of 0, 2 and 4, and here:

1+3=4, 31=2and11=0.

Note that these pairs overlap, and the numbers are reused, which is why we don't get as strong of a condition as above for a composite modulus.